import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;


public class P21 {
	public static int sumProperDivisor(int n) {
		int sum = 0;
		for (int i = 1; i <= n/2; i++) {
			if (n%i == 0) {
				sum += i;
			}
		}
		
		return sum;
	}
	
	public static void main(String[] args) {
		int sum = 0;
		
		for (int i = 1; i <= 10000; i++) {
			int a = sumProperDivisor(i);
			int b = sumProperDivisor(a);
			
			if (i == b && i != a && b <= 10000) {
				System.out.println(i + "," + a);
				sum += i;
			}
		}
		
		
		System.out.println(sum);
	}
}
